package com.ymatou.iapi.login.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.login.parameter.BindWeiXinUseroRequestDtoBean;
import com.ymatou.iapi.login.parameter.UnBindThirdPartyAccountDtoBean;
import com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.iapi.login.service.BindWeiXinUseroRequestDtoCall;
import com.ymatou.iapi.login.service.LoginAuthCall;
import com.ymatou.iapi.login.service.UnBindThirdPartyAccountDtoCall;
import com.ymatou.iapi.login.service.WeiXinUserRequestDtoCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.ThirdpartyUserbind;
import com.ymttest.database.model.ThirdpartyUserbindHistory;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;
/**
*绑定微信账号接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BindWeiXinUseroRequestDto{
	private static BindWeiXinUseroRequestDtoBean bindweixinuserorequestdtoBean;
	private static BindWeiXinUseroRequestDtoCall bindweixinuserorequestdtoCall;
	private static YmtUsersWapper ymtUser;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("绑定微信账号接口");
		ymtUser = new YmtUsersWapper();
	}

	@Before
	public void caseUp() {
		bindweixinuserorequestdtoBean=new BindWeiXinUseroRequestDtoBean();
		bindweixinuserorequestdtoCall=new BindWeiXinUseroRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(bindweixinuserorequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_001() {
		Logger.start(true,"微信账号未绑定过，绑定成功");
		try {
			
			Logger.comment("前置准备：新创建一个用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);			
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result = bindweixinuserorequestdtoCall.getMap();
			
			// 验证返回
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result.get("ResponseCode")).intValue()+"", "验证Code信息");
			Logger.verifyEquals(true, result.get("Success"), "验证操作成功");
			
			// 验证DB
			Logger.comment("验证数据库");
			verifyDB(userId, bindweixinuserorequestdtoBean.getWeiXinUser());
			
			Logger.comment("验证用该账号码头登陆成功");
			LoginAuthCall lac = JUserCallService.login(regbean.getLoginId(), regbean.getPas(), "app", regbean.getClientIp(),regbean.getDeviceId());
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(regbean.getLoginMobile(), lac.getUserData().getLoginMobile(), "验证UserName");

			Logger.comment("验证微信联合登陆成功");
			WeiXinUserRequestDtoCall userRequestDtoCall = JUserCallService.weiXinUserRequestDto(bindweixinuserorequestdtoBean.getWeiXinUser());
			Logger.verifyEquals(ECode.SUCCESS, userRequestDtoCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", userRequestDtoCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_002() {
		Logger.start(true,"微信账号绑定过当前账号，返回已绑定过");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result = bindweixinuserorequestdtoCall.getMap();
			
			Logger.verifyEquals(ECode.SUCCESS, String.valueOf(((Double)result.get("ResponseCode")).intValue()), "验证Code信息");
			
			Logger.comment("再次绑定");
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result2 = bindweixinuserorequestdtoCall.getMap();
			
			// 验证返回
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result.get("ResponseCode")).intValue()+"", "验证Code信息");
			Logger.verifyEquals(true, result.get("Success"), "验证操作成功");
			
			// 验证DB
			Logger.comment("验证数据库");
			verifyDB(userId, bindweixinuserorequestdtoBean.getWeiXinUser());
			
			Logger.comment("验证用该账号码头登陆成功");
			LoginAuthCall lac = JUserCallService.login(regbean.getLoginId(), regbean.getPas(), "app", regbean.getClientIp(),regbean.getDeviceId());
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(regbean.getLoginMobile(), lac.getUserData().getLoginMobile(), "验证UserName");

			Logger.comment("验证微信联合登陆成功");
			WeiXinUserRequestDtoCall userRequestDtoCall = JUserCallService.weiXinUserRequestDto(bindweixinuserorequestdtoBean.getWeiXinUser());
			Logger.verifyEquals(ECode.SUCCESS, userRequestDtoCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", userRequestDtoCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_003() {
		Logger.start(true,"微信账号已绑定过其他账号，绑定失败");
		try {
			Logger.comment("前置准备：新创建一个用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result = bindweixinuserorequestdtoCall.getMap();
			
			UserRegisterInfoRequestDtoBean regbean1 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc1 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean1);
			
			JsonObject registerResult1 = urrc1.getJsonObject().get("Result").getAsJsonObject();
			String token1=registerResult1.get("Token").getAsString();
			int userId1 = urrc1.getUserid();
			
			bindweixinuserorequestdtoBean.setToken(token1);
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result1 = bindweixinuserorequestdtoCall.getMap();			
			
			// 验证返回
			Logger.verifyEquals("401",  String.valueOf(((Double)result1.get("ResponseCode")).intValue()), "验证Code信息");
			Logger.verifyEquals(false, result1.get("Success"), "验证操作成功");
			Logger.verifyEquals("此微信账号已绑定", result1.get("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_004() {
		Logger.start(true,"用户绑定了A微信账号->解绑A微信账号 ->用A登录失败 ->绑定A微信账号->绑定成功 ->用A登录成功");
		try {
			
			Logger.comment("新创建一个用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			Logger.comment("用户绑定了A微信账号");
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);			
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result = bindweixinuserorequestdtoCall.getMap();
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result.get("ResponseCode")).intValue()+"", "验证Code信息");
			
			Logger.comment("解绑A微信账号");
			UnBindThirdPartyAccountDtoBean  unBindThirdPartyAccountDtoBean  = JUserCallService.initUnBindThirdPartyAccountDtoBean(bindweixinuserorequestdtoBean.getWeiXinUser().getUnionId(), ThirdPartyType.WEIXIN, userId);
			UnBindThirdPartyAccountDtoCall  unBindThirdPartyAccountDtoCall  = JUserCallService.unBindThirdPartyAccountDto(unBindThirdPartyAccountDtoBean);
			Logger.verifyEquals("200", unBindThirdPartyAccountDtoCall.getString("ResponseCode"), "验证Code信息");
			
			Logger.comment("验证用该账号码头登陆成功");
			LoginAuthCall lac = JUserCallService.login(regbean.getLoginId(), regbean.getPas(), "app", regbean.getClientIp(),regbean.getDeviceId());
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(regbean.getLoginMobile(), lac.getUserData().getLoginMobile(), "验证UserName");

			Logger.comment("验证微信联合登陆失败");
			WeiXinUserRequestDtoCall userRequestDtoCall = JUserCallService.weiXinUserRequestDto(bindweixinuserorequestdtoBean.getWeiXinUser());
			Logger.verifyEquals(ECode.FAILED400, userRequestDtoCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", userRequestDtoCall.getString("Success"), "验证是否成功");
		
			Logger.comment("用户绑定了A微信账号");
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result1 = bindweixinuserorequestdtoCall.getMap();
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result1.get("ResponseCode")).intValue()+"", "验证Code信息");
			
			Logger.comment("验证用该账号码头登陆成功");
			lac = JUserCallService.login(regbean.getLoginId(), regbean.getPas(), "app", regbean.getClientIp(),regbean.getDeviceId());
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(regbean.getLoginMobile(), lac.getUserData().getLoginMobile(), "验证UserName");

			Logger.comment("验证微信联合登陆成功");
			userRequestDtoCall = JUserCallService.weiXinUserRequestDto(bindweixinuserorequestdtoBean.getWeiXinUser());
			Logger.verifyEquals(ECode.SUCCESS, userRequestDtoCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", userRequestDtoCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_005() {
		Logger.start(true,"用户绑定了A微信账号->解绑A微信账号->绑定B微信账号->绑定成功->用A登录失败 ->用B登录成功");
		try {
			Logger.comment("新创建一个用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			Logger.comment("用户绑定了A微信账号");
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			
			BindWeiXinUseroRequestDtoBean  bindweixinuserorequestdtoBean1 = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);			
			BindWeiXinUseroRequestDtoCall  bindweixinuserorequestdtoCall1 = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean1);
			Map result1 = bindweixinuserorequestdtoCall1.getMap();
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result1.get("ResponseCode")).intValue()+"", "验证Code信息");
			
			Logger.comment("解绑A微信账号");
			UnBindThirdPartyAccountDtoBean  unBindThirdPartyAccountDtoBean  = JUserCallService.initUnBindThirdPartyAccountDtoBean(bindweixinuserorequestdtoBean1.getWeiXinUser().getUnionId(), ThirdPartyType.WEIXIN, userId);
			UnBindThirdPartyAccountDtoCall  unBindThirdPartyAccountDtoCall  = JUserCallService.unBindThirdPartyAccountDto(unBindThirdPartyAccountDtoBean);
			Logger.verifyEquals("200", unBindThirdPartyAccountDtoCall.getString("ResponseCode"), "验证Code信息");
			
			Logger.comment("用户绑定了B微信账号");			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);			
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result2 = bindweixinuserorequestdtoCall.getMap();
		
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result2.get("ResponseCode")).intValue()+"", "验证Code信息");
			Logger.verifyEquals(true, result2.get("Success"), "验证操作成功");
			
			// 验证DB
			Logger.comment("验证数据库");
			verifyDB(userId, bindweixinuserorequestdtoBean.getWeiXinUser());
			
			Logger.comment("验证用该账号码头登陆成功");
			LoginAuthCall lac = JUserCallService.login(regbean.getLoginId(), regbean.getPas(), "app", regbean.getClientIp(),regbean.getDeviceId());
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(regbean.getLoginMobile(), lac.getUserData().getLoginMobile(), "验证UserName");

			Logger.comment("验证A微信联合登陆失败");
			WeiXinUserRequestDtoCall userRequestDtoCall = JUserCallService.weiXinUserRequestDto(bindweixinuserorequestdtoBean1.getWeiXinUser());
			Logger.verifyEquals(ECode.FAILED400, userRequestDtoCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", userRequestDtoCall.getString("Success"), "验证是否成功");
				
			Logger.comment("验证B微信联合登陆成功");
			userRequestDtoCall = JUserCallService.weiXinUserRequestDto(bindweixinuserorequestdtoBean.getWeiXinUser());
			Logger.verifyEquals(ECode.SUCCESS, userRequestDtoCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", userRequestDtoCall.getString("Success"), "验证是否成功");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_006() {
		Logger.start(false,"未输入token，失败");
		try {
			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(null);			
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result = bindweixinuserorequestdtoCall.getMap();
			
			// 验证返回		
			Logger.verifyEquals(ECode.ERROR400, ((Double)result.get("ResponseCode")).intValue()+"", "验证Code信息");
			Logger.verifyEquals(false, result.get("Success"), "验证操作成功");
			Logger.verifyEquals("错误的请求参数|Token不能为空", result.get("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_007() {
		Logger.start(false,"未输入业务端类型");
		try {
			
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);	
			bindweixinuserorequestdtoBean.setClientType(null);
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result = bindweixinuserorequestdtoCall.getMap();
			
			Logger.verifyEquals(ECode.FAILED400, ((Double)result.get("ResponseCode")).intValue()+"", "验证Code信息");
			Logger.verifyEquals(false, result.get("Success"), "验证操作成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_008() {
		Logger.start(false,"未输入微信账号，失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);	
			bindweixinuserorequestdtoBean.getWeiXinUser().setUnionId(null);
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result = bindweixinuserorequestdtoCall.getMap();
			
			Logger.verifyEquals(ECode.ERROR400, ((Double)result.get("ResponseCode")).intValue()+"", "验证Code信息");
			Logger.verifyEquals(false, result.get("Success"), "验证操作成功");
			Logger.verifyEquals("错误的请求参数|第三方用户编号不能为空", result.get("LastErrorMessage"), "验证Msg信息");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_009() {
		Logger.start(true,"用户A绑定了A阿里账号->解绑A阿里账号->用户B绑定A阿里账号->用户B解绑A阿里账号");
		try {
			
			Logger.comment("新创建一个用户A");
			UserRegisterInfoRequestDtoBean regbean1 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc1 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean1);
				
			JsonObject registerResult1 = urrc1.getJsonObject().get("Result").getAsJsonObject();
			String token1=registerResult1.get("Token").getAsString();
			int userId1 = urrc1.getUserid();
			
			Logger.comment("新创建一个用户B");
			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
		
			JsonObject registerResult2 = urrc2.getJsonObject().get("Result").getAsJsonObject();
			String token2=registerResult2.get("Token").getAsString();
			int userId2 = urrc2.getUserid();
		
			Logger.comment("用户A绑定了A微信账号");				
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token1);			
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result1 = bindweixinuserorequestdtoCall.getMap();
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result1.get("ResponseCode")).intValue()+"", "验证Code信息");
			
			Logger.comment("解绑A微信账号");
			UnBindThirdPartyAccountDtoBean  unBindThirdPartyAccountDtoBean  = JUserCallService.initUnBindThirdPartyAccountDtoBean(bindweixinuserorequestdtoBean.getWeiXinUser().getUnionId(), ThirdPartyType.WEIXIN, userId1);
			UnBindThirdPartyAccountDtoCall  unBindThirdPartyAccountDtoCall  = JUserCallService.unBindThirdPartyAccountDto(unBindThirdPartyAccountDtoBean);
			Logger.verifyEquals("200", unBindThirdPartyAccountDtoCall.getString("ResponseCode"), "验证Code信息");
		
			Logger.comment("用户B绑定A阿里账号");
			bindweixinuserorequestdtoBean.setToken(token2);			
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result2 = bindweixinuserorequestdtoCall.getMap();
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result2.get("ResponseCode")).intValue()+"", "验证Code信息");
		
			Logger.comment("用户B解绑A阿里账号");
			UnBindThirdPartyAccountDtoBean  unBindThirdPartyAccountDtoBean2  = JUserCallService.initUnBindThirdPartyAccountDtoBean(bindweixinuserorequestdtoBean.getWeiXinUser().getUnionId(), ThirdPartyType.WEIXIN, userId2);
			UnBindThirdPartyAccountDtoCall  unBindThirdPartyAccountDtoCall2  = JUserCallService.unBindThirdPartyAccountDto(unBindThirdPartyAccountDtoBean2);
			Logger.verifyEquals("200", unBindThirdPartyAccountDtoCall2.getString("ResponseCode"), "验证Code信息");
		
			Logger.comment("验证A微信联合登陆失败");
			WeiXinUserRequestDtoCall userRequestDtoCall = JUserCallService.weiXinUserRequestDto(bindweixinuserorequestdtoBean.getWeiXinUser());
			Logger.verifyEquals(ECode.FAILED400, userRequestDtoCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", userRequestDtoCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_bindWeiXinUseroRequestDto_010() {
		Logger.start(true,"历史微信账号openid和UnionId一致,登入后传入正确UnionId，更新数据成功");
		try {
			
			Logger.comment("前置准备：新创建一个用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int userId = urrc.getUserid();
			
			bindweixinuserorequestdtoBean = JUserCallService.initBindWeiXinUseroRequestDtoBean(token);			
			bindweixinuserorequestdtoCall = JUserCallService.bindWeiXinUseroRequestDto(bindweixinuserorequestdtoBean);
			Map result = bindweixinuserorequestdtoCall.getMap();
			
			// 验证返回
			Logger.verifyEquals(ECode.SUCCESS, ((Double)result.get("ResponseCode")).intValue()+"", "验证Code信息");
			Logger.verifyEquals(true, result.get("Success"), "验证操作成功");
			
			// 验证DB
			Logger.comment("验证数据库");
			verifyDB(userId, bindweixinuserorequestdtoBean.getWeiXinUser());
			
			Logger.comment("验证用该账号码头登陆成功");
			LoginAuthCall lac = JUserCallService.login(regbean.getLoginId(), regbean.getPas(), "app", regbean.getClientIp(),regbean.getDeviceId());
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(regbean.getLoginMobile(), lac.getUserData().getLoginMobile(), "验证UserName");

			Logger.comment("验证微信联合登陆成功");
			WeiXinUserRequestDtoCall userRequestDtoCall = JUserCallService.weiXinUserRequestDto(bindweixinuserorequestdtoBean.getWeiXinUser());
			Logger.verifyEquals(ECode.SUCCESS, userRequestDtoCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", userRequestDtoCall.getString("Success"), "验证是否成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyDB(Integer uid, WeiXinUserRequestDtoBean cq) {
		//TODO 需要检查字段
		JUserWapper ju=new JUserWapper();
		
		Logger.comment("验证thirdparty_userbind");
		ThirdpartyUserbind thirdinfo = ju.selectthirdpartyuserbind(uid).get(0);
		Logger.verifyEquals(cq.getUnionId(), thirdinfo.getThirdPartyId(), "验证ThirdPartyId");
		Logger.verifyEquals(ThirdPartyTypeEnum.WeiXin.getCode(), thirdinfo.getThirdPartyType(), "验证ThirdPartyType");
		
		Logger.comment("验证thirdparty_userbind_history");
		ThirdpartyUserbindHistory thirdinfohist = ju.selectthirdpartyuserbindhistory(uid).get(0);
		Logger.verifyEquals(true, thirdinfohist.getBinding(), "验证binding状态");
		Logger.verifyEquals(cq.getRegSource().getCode(), thirdinfohist.getAppSource(), "验证AppSource");
		Logger.verifyEquals(cq.getClientIp(), thirdinfohist.getClientIp(), "验证ClientIp");
		Logger.verifyEquals(cq.getDeviceId(), thirdinfohist.getDeviceId(), "验证DeviceId");
		Logger.verifyEquals(cq.getEquimentid(), thirdinfohist.getEquimentid(), "验证Equimentid");
		Logger.verifyEquals(cq.getMobile(), thirdinfohist.getLoginMobile(), "验证LoginMobile");
		Logger.verifyEquals(cq.getTSource().getCode(), thirdinfohist.getTerminalSource(), "验证TerminalSource");
		
		Logger.verifyEquals(cq.getCity(), thirdinfohist.getCity(), "验证City");
		Logger.verifyEquals(cq.getProvince(), thirdinfohist.getProvince(), "验证City");
		Logger.verifyEquals(cq.getCountry(), thirdinfohist.getCountry(), "验证Country");
		
		Logger.verifyEquals(cq.getOId(), thirdinfohist.getOpenId(), "验证OpenId");
		Logger.verifyEquals(cq.getHeadimgurl(), thirdinfohist.getHeadimgurl(), "验证Headimgurl");
	}
	
}